package de.openlaboratory.elib.server;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import de.openlaboratory.elib.controller.ElibService;
import de.openlaboratory.elib.core.ComponentRegistry;
import de.openlaboratory.elib.database.hibernate.HibernateUtil;
import de.openlaboratory.elib.model.library.Publication;

public class Command
{
	private String action;
	private String command;
	private Object obj;

	public Command()
	{
		// TODO Auto-generated constructor stub
	}

	public Command(String cmd, String op)
	{
		// TODO Auto-generated constructor stub
	}

	public Command(String cmd)
	{
		// TODO Auto-generated constructor stub
	}

	public String execute(HttpServletRequest request, HttpServletResponse response)
	{
		ElibService service = ComponentRegistry.lookupService(action, command);
		List<Publication> publications = (List<Publication>) service.execute(command, null);
		
		// simulate a database query
//		publications = new ArrayList<Publication>();
//
//		
//		Publication publication = (Publication) HibernateUtil.openSession().get(Publication.class, (long) 9);
//		publications.add(publication);
//		publication = (Publication) HibernateUtil.openSession().get(Publication.class, (long) 14);
//		publications.add(publication);
		
		// set values
		request.setAttribute("publications", publications);

		return "VELOCITY";
	}
}